home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / sMovPlatform.p < prev    next >
Encoding:
Text File  |  1993-09-19  |  2.5 KB  |  107 lines  |  [TEXT/PJMM]

  1. { Platform sprite, moveable version, not faceless }
  2.  
  3. unit sMovPlatForm;
  4.  
  5. interface
  6.  
  7.     uses
  8.         SAT, sPlatForm;
  9.  
  10.     var
  11.         platFace: FacePtr;
  12.  
  13.     procedure InitMovPlatForm;
  14.     procedure SetupMovPlatForm (me: SpritePtr);
  15.     procedure HandleMovPlatForm (me: SpritePtr);
  16.     procedure HitMovPlatForm (me, him: SpritePtr);
  17.  
  18. implementation
  19.  
  20.     procedure InitMovPlatForm;
  21.         var
  22.             i: integer;
  23.     begin
  24.         platFace := GetFace(138);
  25.     end;
  26.  
  27.     procedure SetupMovPlatForm (me: SpritePtr);
  28.         var
  29.             r: Rect;
  30.             pol: PolyHandle;
  31.     begin
  32.         me^.speed.v := -1 + Rand(2) * 2;
  33.         {me^.kind := -2; {Enemy kind}
  34.         me^.face := platFace;
  35.         SetRect(me^.hotRect, 0, 3, 60, 20);
  36.     end;
  37.  
  38.     procedure HandleMovPlatForm (me: SpritePtr);
  39.     begin
  40.         me^.position.v := me^.position.v + me^.speed.v;
  41.         if me^.position.v < 40 then
  42.             me^.speed.v := 1;
  43.         if me^.position.v > offSizeV - 32 then
  44.             me^.speed.v := -1;
  45.  
  46. {Move}
  47.         if me^.speed.v = 0 then
  48.             if me^.position.v > offSizeV div 2 then
  49.                 me^.speed.v := -1
  50.             else
  51.                 me^.speed.v := 1;
  52.  
  53.         me^.layer := -me^.position.v;
  54.     end;
  55.  
  56.     procedure HitMovPlatForm;
  57.         var
  58.             mini, i, min: integer;
  59.             diff: array[1..4] of integer;
  60.     begin
  61.         if him^.Task <> @HandlePlatForm then {check for HandleMovPlatForm too?}
  62.             begin
  63.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
  64.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
  65.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
  66.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
  67.                 mini := 0;
  68.                 min := 10000;
  69.                 for i := 1 to 4 do
  70.                     if min > diff[i] then
  71.                         begin
  72.                             min := diff[i];
  73.                             mini := i;
  74.                         end;
  75.                 case mini of
  76.                     1: {floor}
  77.                         begin
  78.                             him^.position.v := him^.position.v - diff[1] + 2;
  79.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  80.                             if him^.speed.v > 0 then
  81.                                 him^.speed.v := 0;
  82.                         end;
  83.                     2: {cieling (sp?)}
  84.                         begin
  85.                             him^.position.v := him^.position.v + diff[2] + 1;
  86. {No signal here}
  87.                             if him^.speed.v < 0 then
  88.                                 him^.speed.v := -him^.speed.v;
  89.                         end;
  90.                     3: {left}
  91.                         begin
  92.                             him^.position.h := him^.position.h - diff[3] - 1;
  93.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  94.                             if him^.speed.h > 0 then
  95.                                 him^.speed.h := -him^.speed.h;
  96.                         end;
  97.                     4: {right}
  98.                         begin
  99.                             him^.position.h := him^.position.h + diff[4] + 1;
  100.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  101.                             if him^.speed.h < 0 then
  102.                                 him^.speed.h := -him^.speed.h;
  103.                         end;
  104.                 end;{case}
  105.             end; {if}
  106.     end; {HitMovPlatForm}
  107. end.{of unit}